<?php

namespace App\Models;

use App\Common\Traits\HasAttachments;
use Illuminate\Database\Eloquent\SoftDeletes;
use Spatie\Activitylog\Traits\LogsActivity;

/**
 * Class WebsiteLetter
 * @package App\Models
 */
class WebsiteLetter extends Base
{
    use SoftDeletes, HasAttachments, LogsActivity;

    /**
     * 范围: 全部
     */
    const RANGE_TYPE_ALL = 1;

    /**
     * 范围: 指定人员
     */
    const RANGE_TYPE_DESIGNATED = 2;

    /**
     * 附件类型: 图片
     */
    const ATTACHMENT_TYPE_PIC = 1;

    /**
     * 附件类型: 文件 (xls, xlsx)
     */
    const ATTACHMENT_TYPE_FILE = 2;

    protected $table = 'website_letter';

    public function agentLetter()
    {
        return $this->hasMany(AgentWebsiteLetter::class, 'website_letter_id');
    }

    /**
     * 自定义操作日志 说明
     * @param $eventName
     * @return string
     */
    public function getDescriptionForEvent(string $eventName): string
    {
        if (in_array($eventName, ['created', 'deleted'])) {
            switch ($eventName) {
                case 'created':
                    return '创建站内信:' . $this['title'] ?? '';
                case 'deleted':
                    return sprintf('删除站内信: %s', $this['title'] ?? '');
            }
        }

        return '';
    }
}
